package c6;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class CollectorHarness {
    public static void main(String[] args){
        long fastest=Long.MAX_VALUE;
        for(int i=0;i<10;i++){
            long start=System.nanoTime();
            //partitionPrimes(1000000);
            partitionPrimesByCustomCollector(1000000);
            long duration=(System.nanoTime()-start)/1000000;
            if(duration<fastest) fastest=duration;
            System.out.println("Fastest execute done in "+fastest+"msecs");
        }
    }

    public static Map<Boolean,List<Integer>> partitionPrimes(int n){

        return IntStream.rangeClosed(2,n).boxed()
                .collect(Collectors.partitioningBy(Partitioning::isPrime));
    }

    public static Map<Boolean,List<Integer>> partitionPrimesByCustomCollector(int n){
        return IntStream.rangeClosed(2,n).boxed()
                .collect(new PrimeNumbersCollector());
    }
}
